package com.yjd.comm.util;

import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadUtil {

	private ThreadUtil() {
	}

	private static ThreadPoolExecutor poolTaskExecutor;

	public static ThreadPoolExecutor getThreadPoolTaskExecutor() {
		if (poolTaskExecutor == null) {
			synchronized (ThreadUtil.class) {
				if (poolTaskExecutor == null) {
					// corePoolSize:10 maximumPoolSize:3000 keepAliveTime:60s workQueue:任务等待队列长度
					poolTaskExecutor = new ThreadPoolExecutor(5, 200, 60L, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(2000));
				}
			}
		}
		return poolTaskExecutor;
	}

	public static Future submit(Runnable task){
		return getThreadPoolTaskExecutor().submit(task);
	}
}
